<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>src\admin\controller\mob.js</title>
  
    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
    <link rel="stylesheet" href="../assets/css/main.css" id="site_styles">
    <link rel="stylesheet" href="../assets/vendor/bootstrap/css/bootstrap.min.css">
    <link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
</head>
<body class="yui3-smart">
 <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
        <div class="container-fluid">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
               <a class="navbar-brand mainlogo" href="/static/doc/index.html">
             
            <img alt="" src="../assets/css/logo.png" title="">
            
                
          </a>
            </div>
            <div id="navbar" class="navbar-collapse collapse">
                 <ul class="nav navbar-nav">
                    
                    <li><a href="/home/index/index">首页</a>
                    </li>
                    
                    <li><a href="/static/doc/index.html">文档</a>
                    </li>
                    
                    <li><a href="/admin/index/index">演示</a>
                    </li>
                    
                    <li><a href="/home/index/log">日志</a>
                    </li>
                    
                </ul>
               <div class="navbar-form navbar-right filterAPi" autocomplete="off">
                <input type="text" id='txtSearchAPI' class="form-control search-query" placeholder="Search for API" />
                 <ul id="filterList" class="filterItems dropdown-menu" role="menu"></ul>
                </div>
            </div>
        </div>
    </nav>
    <div id="sidebar">
    <h3>Modules/Classes</h3>
        <div id="api-tabview-filter">
            <input id='txtSearch' type="search" class="form-control" placeholder="Type to filter Modules/Classes">
        </div>
        <dl id="sidebar_list">
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/admin.controller.html">admin.controller</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/admin.controller.base.html">admin.controller.base</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.controller.code.html">admin.controller.code</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.controller.index.html">admin.controller.index</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.controller.mob.html">admin.controller.mob</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/admin.model.html">admin.model</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/admin.model.code.html">admin.model.code</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.code_list.html">admin.model.code_list</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.code_lookup.html">admin.model.code_lookup</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.groupuser.html">admin.model.groupuser</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.groupuser_add.html">admin.model.groupuser_add</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.log.html">admin.model.log</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.login.html">admin.model.login</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.privilege.html">admin.model.privilege</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.teamuser.html">admin.model.teamuser</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.teamuser_add.html">admin.model.teamuser_add</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.user.html">admin.model.user</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/cmpage.controller.html">cmpage.controller</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/cmpage.controller.base.html">cmpage.controller.base</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.controller.mob.html">cmpage.controller.mob</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.controller.module.html">cmpage.controller.module</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.controller.page.html">cmpage.controller.page</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.controller.utils.html">cmpage.controller.utils</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/cmpage.logic.html">cmpage.logic</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/cmpage.logic.page.html">cmpage.logic.page</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/cmpage.model.html">cmpage.model</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/cmpage.model.area.html">cmpage.model.area</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.base.html">cmpage.model.base</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.file_list.html">cmpage.model.file_list</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.page.html">cmpage.model.page</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.page_excel.html">cmpage.model.page_excel</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.page_lookup.html">cmpage.model.page_lookup</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.page_mob.html">cmpage.model.page_mob</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.utils.html">cmpage.model.utils</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.cmpage_global.html">cmpage.cmpage_global</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.cmpage_global_flow.html">cmpage.cmpage_global_flow</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/demo.model.html">demo.model</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/flow.model.proc_assign.html">flow.model.proc_assign</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.appr.html">cmpage.model.appr</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.model.proc.html">flow.model.proc</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.model.task.html">flow.model.task</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.model.task_act.html">flow.model.task_act</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.model.task_act_appr.html">flow.model.task_act_appr</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/flow.controller.html">flow.controller</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/flow.controller.act.html">flow.controller.act</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.controller.base.html">flow.controller.base</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.controller.proc.html">flow.controller.proc</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.controller.task.html">flow.controller.task</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.controller.task_act.html">flow.controller.task_act</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/flow.model.html">flow.model</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/flow.model.act.html">flow.model.act</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.model.act_path.html">flow.model.act_path</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
        </dl>
</div>
   
    <div class="stdoc-content">
        <!--     <form id="options-form" class="form-inline pull-right">
        Show:
        <label for="api-show-inherited" class="checkbox">
            <input type="checkbox" id="api-show-inherited" checked>
            Inherited
        </label>

        <label for="api-show-protected" class="checkbox">
            <input type="checkbox" id="api-show-protected">
            Protected
        </label>

        <label for="api-show-private" class="checkbox">
            <input type="checkbox" id="api-show-private">
            Private
        </label>
        <label for="api-show-deprecated" class="checkbox">
            <input type="checkbox" id="api-show-deprecated">
            Deprecated
        </label>

    </form>

 -->
        <div class="apidocs">
            <div id="docs-main">
                <div class="content">
                    <div class="page-header">
    <h1>src\admin\controller\mob.js <small>File</small></h1>
</div>

<div class="file">
    <pre class="prettyprint linenums" id='src_code'>
&#x27;use strict&#x27;;
// +----------------------------------------------------------------------
// | CmPage [ 通用页面框架 ]
// +----------------------------------------------------------------------
// | Licensed under the Apache License, Version 2.0
// +----------------------------------------------------------------------
// | Author: defans &lt;defans@sina.cn&gt;
// +----------------------------------------------------------------------
/**
 @module admin.controller
 */

/**
 * 移动端APP的admin模块的RUL接口，包括用户登录、取菜单、版本信息等
 * 由于移动端和PC端的表现方式和功能有所差别，因此部分URL接口单独实现
 * @class admin.controller.mob
 */
import Base from &#x27;./base.js&#x27;;

export default class extends Base {
     /**
     *  取APP的版本信息，用户比较APP的版本，并自动更新资源包
     * @method getVersion
     * @return {json} 版本信息，包括新版资源包的URL
     */
    async getVersionAction(){
        let md = await this.model(&#x27;code&#x27;).getCodeById(345);
        return this.json({version:md.c_desc, url:md.c_object,memo :md.c_memo});
    }

    /**
     * 取账套列表
     * @method getGroups
     * @return {json}   HTML片段，用于下拉选择登陆账套等
     */
    async getGroupsAction(){
        let list = await this.model(&#x27;code&#x27;).getGroups();
        let html =[];
        html.push(&#x27;&lt;select id=&quot;group&quot;&gt;&#x27;);
        for(let md of list){
            html.push(&#x60;&lt;option value=&quot;${md.id}&quot;&gt;${md.c_name}&lt;/option&gt;&#x60;);
        }

        html.push(&#x27;&lt;/select&gt;&#x27;);
        let ret =  html.join(&#x27;&#x27;);
        //console.log(ret);
        return this.success(ret);
    }

    /**
     * 取APP菜单和按钮的列表
     * @method getMenus
     * @return {json}  备注中设置&#x27;btn&#x27;的为按钮，其他为菜单
     */
    async getMenusAction(){
        let user = await this.session(&#x27;user&#x27;);
         //console.log(user);
        let menuList = await this.model(&#x27;privilege&#x27;).userGetPrivilegeTree(user.id,user.c_role, 1147);
        let btns = [];
        let navs = [];
        let k =0;
        for(let menu of menuList){
            if(menu.c_type === &#x27;N&#x27; &amp;&amp; menu.isAllow){
                let nav ={id:menu.id, title:menu.c_name, modules:[]};
                for(let item of menuList){
                    if(item.c_pid === nav.id &amp;&amp; item.c_type === &#x27;M&#x27;  &amp;&amp; (menu.c_memo !== &#x27;btn&#x27; || k &gt;=3 )){
                        nav.modules.push({title:item.c_name, modulename:item.c_object.replace(&#x27;mob.&#x27;,&#x27;&#x27;), parmsUrl:item.c_other,
                            url: think.isEmpty(item.c_desc) ? &#x27;../cmpage/cmpage-list.html&#x27; : item.c_desc });
                    }
                }
                navs.push(nav);
            }else if(menu.c_type === &#x27;M&#x27; &amp;&amp; menu.c_memo === &#x27;btn&#x27; &amp;&amp; k &lt;3  &amp;&amp; menu.isAllow){
                k ++;
                btns.push({title:menu.c_name, modulename:menu.c_object.replace(&#x27;mob.&#x27;,&#x27;&#x27;), parmsUrl:menu.c_other,
                    url: think.isEmpty(menu.c_desc) ? &#x27;../cmpage/cmpage-list.html&#x27; : menu.c_desc });
            }
        }

        return this.json({menus:navs, btns:btns});
    }

  /**
   * 用户登录,包括验证账套、角色等
   * @method    login
   * @return {json}
   */
    async loginAction(){
        //let vb ={msg:&#x27;请选择您有权限登录的账套。&#x27;};
        let vb ={msg:&#x27;演示用户：defans  密码：123456&#x27;};
        vb.groups = await this.model(&#x27;code&#x27;).getGroups();

        let user = await this.model(&#x27;user&#x27;).getUserByLogin(this.post(&#x27;loginName&#x27;),this.post(&#x27;loginPwd&#x27;),true);
        //cmpage.debug(user);
        if(!think.isEmpty(user)){
            if(user.c_status != 0){
                return this.json({ id :0, msg : &quot;请等候管理员审核，谢谢！&quot; });
            }
            //判断是否有权限登录所选择的账套
            let groups = this.model(&#x27;groupuser&#x27;).getLoginGroups(this.post(&#x27;loginGroup&#x27;), user.id);
            if(think.isEmpty(groups)){
                return this.json({ id :0, msg : &quot;对不起，您不能登录该账套！&quot; });
            }else {
                user.ip = this.ip();
                user.urlLast = &#x27;/admin/mob/index&#x27;;
                user.groupID = parseInt(this.post(&#x27;loginGroup&#x27;));
                user.groupName = await this.model(&#x27;code&#x27;).getNameById(user.groupID);
                user.groups = groups;
                await this.model(&#x27;login&#x27;).addLogin(user);
                await this.session(&#x27;user&#x27;, user);
                return this.json(user);
            }
        }else{
            return this.json({ id :0, msg : &quot;用户名或密码错误！&quot; });
        }
    }

    /**
     * 退出登录,同时注销session 设置
     * @method    exitLogin
     * @return {json}
     */
    async exitLoginAction(){
        await this.model(&#x27;login&#x27;).exitLogin(await this.session(&#x27;user&#x27;));
        await this.session(&#x27;user&#x27;,null);
        return this.redirect(&#x27;/admin/index/login&#x27;);
    }

    /**
     * 修改用户密码
     * @method   loginPwdEdit
     * @return {json}
     */
    async loginPwdEditAction(){
        if(this.method() === &#x27;get&#x27;){
            return this.display();
        }else{
            let user = await this.session(&#x27;user&#x27;);
            await this.model(&#x27;t_user&#x27;).where({id:user.id}).update({c_login_pwd:think.md5(this.post(&#x27;newPwd&#x27;))});
            await this.cache(&quot;users&quot;,null);  //清除users缓存
            return this.json({statusCode:200, message:&#x27;密码已修改，请牢记！&#x27;});
        }
    }



}

    </pre>
</div>

                </div>
            </div>
        </div>
    </div>
<a id="gotoTop" class='well well-small' href='#'>
    Top
</a>
<script src="../assets/vendor/jquery/jquery-1.8.2.min.js"></script>
<script src="../assets/vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script src="../assets/js/config.js"></script>
<script src="../assets/js/doc.js"></script>
</body>
</html>
